

@EXTERNAL FUNCTION getValue : DINT
    VAR_INPUT
        n : REF_TO STRING;
        t : REF_TO STRING;
        d : REF_TO STRING;
    END_VAR
END_FUNCTION


@EXTERNAL FUNCTION setValue : DINT
    VAR_INPUT
        n : REF_TO STRING;
        t : REF_TO STRING;
        d : REF_TO STRING;
    END_VAR
END_FUNCTION

@EXTERNAL FUNCTION out : DINT
    VAR_INPUT
        t : REF_TO STRING;
    END_VAR
END_FUNCTION

@EXTERNAL FUNCTION outW : DINT
    VAR_INPUT
        t : REF_TO WSTRING;
    END_VAR
END_FUNCTION

@EXTERNAL FUNCTION outInt : DINT
    VAR_INPUT
        n : DINT;
    END_VAR
END_FUNCTION

@EXTERNAL FUNCTION outFloat : DINT
    VAR_INPUT
        n : REAL;
    END_VAR
END_FUNCTION

TYPE _StructOfStudent: STRUCT
    name: STRING[255];
    age: INT;
    tt: DINT;
END_STRUCT END_TYPE


FUNCTION main : DINT
    VAR
        P : STRING := '';
        Q : WSTRING := "";
        
        int_array : ARRAY[0..2] OF DINT;
        bool_array : ARRAY[0..2] OF BOOL;

        R : CHAR := 'A';
		
		C : DINT := 0;
		ty_date : DATE := 0;
		ty_time : TIME := 0;

		N : REAL := 0.0;

        StructOfStudent : _StructOfStudent;
        pp : POINTER to STRING;
	END_VAR


    

    out(ADR('STRING Test:\n'));
    getValue(ADR('P'),ADR('STRING'),ADR(P));
    out(ADR(P));
   
    getValue(ADR('P'),ADR('STRING'),ADR(P));
    out(ADR(P));
    out(ADR('=============================='));

    out(ADR('WSTRING Test:\n'));
    getValue(ADR('Q'),ADR('WSTRING'),ADR(Q));
    outW(ADR(Q));
    getValue(ADR('Q'),ADR('WSTRING'),ADR(Q));
    outW(ADR(Q));
	
	out(ADR('=============================='));	
	out(ADR('REAL Test:\n'));
	N := 0.0;
    getValue(ADR('N'),ADR('REAL'),ADR(N));
    outFloat(N);
	out(ADR('=============================='));
	
	out(ADR('TIME Test:\n'));
	ty_time := 0;
	getValue(ADR('ty_time'),ADR('TIME'),ADR(ty_time));
	outInt(ty_time);
	
    out(ADR('=============================='));
    out(ADR('CHAR Test:\n'));
    getValue(ADR('R'),ADR('CHAR'),ADR(R));
    outInt(R);
    
    getValue(ADR('R'),ADR('CHAR'),ADR(R));
    outInt(R);
    out(ADR('=============================='));

    out(ADR('Array_INT Test:\n'));
    out(ADR('Array_INT getValue:'));
    getValue(ADR('Y'),ADR('Array_INT'),ADR(int_array));
    outInt(int_array[0]);
    outInt(int_array[1]);

	out(ADR('=============================='));
    out(ADR('DATE Test:\n'));
	ty_date := 0;
    getValue(ADR('ty_date'),ADR('DATE'),ADR(ty_date));
    outInt(ty_date);

	out(ADR('DINT Test:\n'));
    getValue(ADR('C'),ADR('DINT'),ADR(C));
    outInt(C);
    out(ADR('=============================='));
	

    out(ADR('Array_BOOL Test:\n'));
    out(ADR('Array_BOOL getValue:'));
    getValue(ADR('Z'),ADR('Array_BOOL'),ADR(bool_array));
    outInt(bool_array[0]);
    outInt(bool_array[1]);
   
    out(ADR('=============================='));


    out(ADR('StructOfStudent Test:\n'));
    out(ADR('StructOfStudent getValue:\n'));
    getValue(ADR('StructOfStudent'),ADR('STRUCT'),ADR(StructOfStudent));
    out(ADR(StructOfStudent.name));
    outInt(StructOfStudent.age);
    outInt(StructOfStudent.tt);


    out(ADR('==============ptr========='));
    getValue(ADR('P'),ADR('STRING'),pp);
    out(pp);

END_FUNCTION
